<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/js/jquery.js"></script>
    <link rel="stylesheet" href="/css/element-ui@2.13.2.index.css">
    <script src="/js/vue.min.js"></script>
    <script src="/js/vue-resource.min.js"></script>
    <script src="/js/index.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/axios.min.js"></script>
    <!-- 字体图标css的引入 -->
    <link rel="stylesheet" href="/css/font_830376_qzecyukz0s.css">
    <link rel="stylesheet" href="/css/color-dark.css">
    <link rel="stylesheet" href="/css/icon.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/base.css">
    <title></title>
</head>

<body>
<div id="manage">
    <!-- 头部 -->
    <div class="wrapper">
        <!-- 头部 -->
        <div class="header">
            <!-- 折叠按钮 -->
            <div class="header-left">
                进存销系统
            </div>

            <!-- <div class="logo">后台管理系统</div> -->
            <div class="header-right">
                <div class="header-user-con">
                    <!-- 全屏显示 -->
                    <div class="btn-fullscreen" @click="handleFullScreen">
                        <el-tooltip effect="dark" :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
                            <i class="el-icon-rank"></i>
                        </el-tooltip>
                    </div>
                    <div class="user-avator">
                        <img src="/image/img.jpg" />
                    </div>
                    <!-- 用户名下拉菜单 -->
                    <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                            <span class="el-dropdown-link">
                                {{username}}
                                <i class="el-icon-caret-bottom"></i>
                            </span>
                        <el-dropdown-menu slot="dropdown">
                            <a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
                                <el-dropdown-item>项目仓库</el-dropdown-item>
                            </a>
                            <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </div>
        </div>

        <!-- 侧边部分 -->
        <div data-v-68d67528="" class="sidebar">
            <ul data-v-68d67528="" role="menubar" class="sidebar-el-menu el-menu side-ul"
                style="background-color: rgb(50, 65, 87);">
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item"
                    style="padding-left: 20px; color: rgb(191, 203, 217); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-home"></i><span data-v-68d67528="">首页</span></li>
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item  is-active"
                    style="padding-left: 20px; color: rgb(191, 203, 217); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-calendar"></i><span data-v-68d67528="">进货</span>
                </li>
                <li data-v-68d67528="" role="menuitem" tabindex="-1" class="el-menu-item"
                    style="padding-left: 20px; color: rgb(32, 160, 255); background-color: rgb(50, 65, 87);"><i
                        data-v-68d67528="" class="el-icon-lx-global"></i><span data-v-68d67528="">销售</span></li>
            </ul>
        </div>

        <!-- 内容部分 -->
        <div class="content-box">
            <div class="content">
                <div>
                    <div class="crumbs">
                        <el-breadcrumb separator="/">
                            <el-breadcrumb-item>{{title}}</el-breadcrumb-item>
                        </el-breadcrumb>
                    </div>
                    <div class="container">
                        <div>
                            <el-page-header @back="back"></el-page-header>
                        </div>
                        <br><br>
                        <div>
                            <el-input type="text" label="商品编号" placeholder="请输入商品编号"
                                      v-model="goodsId" style="width: 150px; margin-right: 50px"></el-input>
                            <el-button type="primary" @click="addGoods" style="margin-right: 50px">添加商品</el-button>
                            <i class="el-icon-shopping-cart-full"></i>
                            <el-input type="text" v-model="amount" style="width: 150px;"></el-input>
                        </div>
                        <br><br>
                        <div>
                            <label>实收金额</label>
                            <el-input label="实收金额" placeholder="请输入实收金额"
                                      v-model="sellData.actuallyMoney" style="width: 150px; margin-right: 50px"></el-input>
                            <label>找零</label>
                            <el-input label="找零" placeholder="请输入找零金额"
                                      v-model="sellData.change" style="width: 150px; margin-right: 50px"></el-input>
                            <el-select v-model="sets[0].model_version" style="width: 100%" name="model_version" placeholder="请选择">
                                <el-option
                                        v-for="item in model_versionOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                        <br><br>
                        <div>
                            <el-table
                                    ref="multipleTable"
                                    :data="tableData"
                                    tooltip-effect="dark"
                                    style="width: 100%"
                                    @selection-change="handleSelectionChange">
                                <el-table-column
                                        prop="gId"
                                        label="商品编号"
                                        width="120">
                                    <template slot-scope="scope">{{ scope.row.gId }}</template>
                                </el-table-column>
                                <el-table-column
                                        prop="gName"
                                        label="商品名称"
                                        width="120">
                                    <template slot-scope="scope">{{ scope.row.gName }}</template>
                                </el-table-column>
                                <el-table-column
                                        prop="gPrice"
                                        label="商品单价"
                                        width="120">
                                    <template slot-scope="scope">{{ scope.row.gPrice }}</template>
                                </el-table-column>
                                <el-table-column
                                        prop="gNum"
                                        label="商品数量"
                                        width="120">
                                    <template slot-scope="scope">1</template>
                                </el-table-column>
                                <el-table-column label="操作" width="180" align="center">
                                    <template slot-scope="scope">
                                        <el-button type="text"  size="small" icon="el-icon-delete" class="red"
                                                   @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <div style="margin-top: 20px">
                                <el-button @click="sell()">完成订单</el-button>
                            </div>
<!--                            <div style="margin-top: 20px">-->
<!--                                <el-button @click="toggleSelection()">取消选择</el-button>-->
<!--                            </div>-->
                        </div>
                    </div>
                </div>
                <div>
                    <!--显示查询结果-->
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    var manage = new Vue({
        el: '#manage',
        data: {
            param: {
                username: 'Jee',
                password: '123123',
            },
            rules: {
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
            },
            fullscreen: false,
            name: 'Jee',
            message: 2,
            collapse: false,
            title: '销售',
            readonly: true,
            btnText: '添加',
            inline: true,
            dialogVisible: false,
            // 返回的结果集
            tableData: [],
            tableIndex: 0,
            pageTotal: 0,
            query: {
                pageIndex: 1,
                pageSize: 10
            },
            goodsId: null,
            amount: null,
            sellData: {
                actuallyMoney: 0,
                change: 0,
                payMethods: [
                    // 0
                ],
                sellGoods: [
                    // {
                    //     goodsId: 0,
                    //     goodsNum: 0,
                    //     goodsPrice: 0
                    // }
                ],
                storeId: 1
            },
        },
        watch: {

        },
        computed: {
            username() {
                let username = localStorage.getItem('ms_username');
                return username ? username : this.name;
            }
        },
        mounted() {

        },
        created() {

        },
        methods: {

            // 添加商品
            addGoods() {
                // 获取输入输入框的商品编号
                if(this.goodsId == null) {
                    this.$message.error("请输入商品编号");
                } else {
                    // 将商品编号转化为int类型 调用后台接口
                    var s = this.goodsId;
                    var goodsId = parseInt(s);
                    axiosGetRequst("/invoicing/goods/detail/1/" + goodsId, null)
                        .then(result => {
                            if (result.code == 200) {
                                var sellGoods = {
                                    gId: result.data.gid,
                                    gName: result.data.gname,
                                    gPrice: result.data.gprice
                                };
                                this.$set(this.tableData, this.tableIndex, sellGoods);  // 数组，下标，值
                                this.tableIndex = this.tableIndex + 1;
                                // 计算总价格
                                this.amount = this.amount + result.data.gprice;
                            } else{
                                this.$message.error(result.msg);
                            }
                        });
                }
                console.log(this.tableData)
            },

            // 删除
            handleDelete(index, row) {
                // 二次确认删除
                this.$confirm('确定要删除吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    // 在tableData中删除记录
                    this.tableData.splice(index, 1);
                    this.amount = this.amount - row.gPrice;
                }).catch(() => { });
            },

            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            },

            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },


            back() {
                window.history.back(-1);
            },

            onSubmit() {
                var form = new FormData();
                form.append('sets[0].set_name', this.sets[0].set_name);
                form.append('sets[0].model_version', this.sets[0].model_version);
                form.append('optional.top_n', this.optional.top_n);
                form.append('optional.matched_similar', this.optional.matched_similar);
                form.append('file', this.file);
                axiosPostFormDataRequest('/api/search', form)
                    .then(result => {
                        if (result.status == 200) {
                            this.tableData = result.data.items;
                            this.$message.success('查询人脸用户成功');
                        } else {
                            this.$message.error(result.message);
                        }
                        this.pageTotal = this.tableData.length;
                    })
            },
            cancel() {
                window.history.back(-1);
            },

            // 用户名下拉菜单选择事件
            handleCommand(command) {
                if (command == 'loginout') {
                    localStorage.removeItem('ms_username');
                    window.localStorage["token"] = '';
                    window.location.href = 'login';
                }
            },
            // 全屏事件
            handleFullScreen() {
                let element = document.documentElement;
                if (this.fullscreen) {
                    if (document.exitFullscreen) {
                        document.exitFullscreen();
                    } else if (document.webkitCancelFullScreen) {
                        document.webkitCancelFullScreen();
                    } else if (document.mozCancelFullScreen) {
                        document.mozCancelFullScreen();
                    } else if (document.msExitFullscreen) {
                        document.msExitFullscreen();
                    }
                } else {
                    if (element.requestFullscreen) {
                        element.requestFullscreen();
                    } else if (element.webkitRequestFullScreen) {
                        element.webkitRequestFullScreen();
                    } else if (element.mozRequestFullScreen) {
                        element.mozRequestFullScreen();
                    } else if (element.msRequestFullscreen) {
                        // IE11
                        element.msRequestFullscreen();
                    }
                }
                this.fullscreen = !this.fullscreen;
            },
        }
    })

</script>
</body>

</html>